<template>
  <div>
    <download-item :data="item"></download-item>
  </div>
</template>
<script>
  import DownloadItem from '../shared/DownloadItem.vue';
  import {
    pagination,
    search,
    home
  } from 'fac/mixin.js';
  import {
    NS
  } from 'fac/constant';
  import {
    mapState
  } from 'vuex';
  const NS_HOME = NS.HOME;
  const NS_SEARCH = NS.SEARCH;
  const NS_PERSONAL = NS.PERSONAL;
  const NS_PAGINATION = NS.PAGINATION;
  export default {
    name: 'hot-download',
    mixins: [pagination, search, home],
    beforeRouteUpdate(to, from, next) {
      //当搜索字符串变化时,路由发生改变,重新请求数据
      console.log(to);
      console.log(this.search);
      console.log(this.query);
      // this.fetchData()
      next();
    },
    data() {
      return {
        item: {
          id: 1,
          title: '测试测试',
          date: '2017-5-23'
        }
      }
    },
    computed: {
      // ...mapState(NS_SEARCH, ['search']),
      // ...mapState(NS_HOME, ['query'])
    },
    methods: {
      fetchData() {
        console.log('fetchData');
        this.$http({
          url: this.api.GetHotDownload,
          params: {
            search: this.search
          }
        }).then(function (response) {
          console.log(response.data);
          console.log(response.status);
          console.log(response.statusText);
          console.log(response.headers);
          console.log(response.config);
        });
      }
    },
    mounted() {
      //请求数据

      console.log(this.search);
      console.log(this.query)
      this.isNotIndexHomePage && this.renderPagination({
        total: 500,
        currentPage: 3
      });
    },
    components: {
      DownloadItem
    }
  }

</script>
